// -*- coding: utf-8 -*-
#ifndef SYNCDIALOG_H
#define SYNCDIALOG_H

#include <QDialog>
#include <QTextEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFile>
#include <QTextStream>
#include <QMessageBox>
#include <QKeyEvent>
#include "diffhighlighter.h"
#include "filecomparator.h"

QT_BEGIN_NAMESPACE
namespace Ui {
class SyncDialog;
}
QT_END_NAMESPACE

class SyncDialog : public QDialog
{
    Q_OBJECT

public:
    SyncDialog(const QString &leftFilePath, const QString &rightFilePath, QWidget *parent = nullptr);
    ~SyncDialog();

protected:
    void closeEvent(QCloseEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;

private slots:
    void on_leftToRightButton_clicked();
    void on_rightToLeftButton_clicked();
    void on_saveButton_clicked();
    void on_textChanged();

private:
    Ui::SyncDialog *ui;
    QString m_leftFilePath;
    QString m_rightFilePath;
    DiffHighlighter *m_leftHighlighter;
    DiffHighlighter *m_rightHighlighter;
    FileComparator *m_fileComparator;
    bool m_isModified;
    
    void loadFileContents();
    void saveFile(const QString &filePath, const QString &content);
    void updateDiffHighlight();
    void markAsModified();
};

#endif // SYNCDIALOG_H